package com.bckj.fastboot.iot.data.mysql.repository;

import com.baomidou.mybatisplus.extension.repository.CrudRepository;
import com.bckj.fastboot.core.lang.model.PageResult;
import com.bckj.fastboot.core.page.PageSupport;
import com.bckj.fastboot.iot.common.dto.query.IotStatusDataQuery;
import com.bckj.fastboot.iot.common.dto.request.IotStatusDataRequest;
import com.bckj.fastboot.iot.common.dto.response.IotStatusDataResponse;
import com.bckj.fastboot.iot.common.repository.IotStatusDataRepository;
import com.bckj.fastboot.iot.data.mysql.convert.IotStatusDataConvert;
import com.bckj.fastboot.iot.data.mysql.entity.IotStatusData;
import com.bckj.fastboot.iot.data.mysql.mapper.IotStatusDataMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * IotStatusDataRepositoryImpl
 *
 * @author wfc
 **/
@Repository
@RequiredArgsConstructor
public class IotStatusDataRepositoryImpl extends CrudRepository<IotStatusDataMapper, IotStatusData>
implements IotStatusDataRepository {

    private final IotStatusDataConvert iotStatusDataConvert;

    @Override
    public boolean save(IotStatusDataRequest request) {
        var entity = iotStatusDataConvert.toEntity(request);
        return save(entity);
    }

    @Override
    public IotStatusDataResponse details(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public List<IotStatusDataResponse> findList(IotStatusDataQuery query) {
        return baseMapper.findList(query);
    }

    @Override
    public PageResult<IotStatusDataResponse> page(Pageable page, IotStatusDataQuery query) {
        var result = PageSupport.page(page, query, this::findList);
        return PageResult.of(result);
    }
}
